﻿namespace Microsoft.AspNetCore.Http
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Abp.Json;
    using Microsoft.AspNetCore.Http;
    using Newtonsoft.Json;
    using FFF.Test.Entity.FW.View;
    using FFF.Test.Util.Consts;
    using Ydm.Extensions;

    /// <summary>
    /// session的扩展
    /// </summary>
    public static class CookieExtensions
    {
        /// <summary>
        /// 获取公司信息
        /// </summary>
        /// <param name="cookie">cookie信息</param>
        /// <returns>获取公司Cookie</returns>
        public static CookieBuInfo GetBuInfo(this IRequestCookieCollection cookie)
        {
            var buCookie = cookie["BuInfo"];
            if (!buCookie.IsNullOrEmpty())
            {
                CookieBuInfo buInfo = JsonConvert.DeserializeObject<CookieBuInfo>(buCookie);
                return buInfo;
            }
            else
            {
                return null;
            }
        }
    }

    /// <summary>
    /// 获取当前公司的信息
    /// </summary>
    public class CookieBuInfo
    {
        /// <summary>
        /// 公司ID
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// BuName
        /// </summary>
        public string BuName { get; set; }
    }
}
